<template>
	<view>
		<u-form class="u-flex u-flex-wrap u-col-center u-row-center">
			<u-form-item>
				<u-input v-model="form.content" 
						 type="textarea" 
						 auto-height
						 border="true"
						 border-color="#5CACEE"
						 placeholder="请输入温馨提示内容,最多25个字"/>
			</u-form-item>
			<u-form-item class="u-flex u-col-center u-row-center">
				<u-button type="success" size="medium" @click="submit">提交</u-button>
			</u-form-item>
		</u-form>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	import { updatePromptInfo } from '../../../utils/index.js'
	export default {
		data() {
			return {
				form: {
					content: '',								//当前提示的内容
					sectionNo: ''								//工段编号
				}
			}
		},
		methods: {
			//提交按钮绑定的函数，将温馨提示的内容发送到后台
			//将提示信息的输入为空的状态的判断放在前端，不再向后台请求数据
			async submit() {
				if(this.form.content == '') {
					this.$refs.uTips.show({
						title: '温馨提示信息不能为空！',
						type: 'warning',
						duration: '2000'
					})
				} else {
					const query = Object.assign({},this.form)
					const { data } = await updatePromptInfo(query)
					const errMsg = data.msg
					if(data.code == '1'){
						this.$refs.uTips.show({
							title: '修改成功',
							type: 'success',
							duration: '2000'
						})
					} else {
						this.$refs.uTips.show({
							title: errMsg,
							type: 'warning',
							duration: '2000'	
						})
					}
				}
			}
		},
		// 路由跳转传递过来的参数
		// 传递过来的参数与data中form的参数是一致的
		onLoad(option) {
			this.form = Object.assign({},option)
		}
	}
</script>

<style lang="scss">
 ::v-deep .u-input {
	margin-top: 60rpx;
	width: 520rpx;
}
</style>
